package com.wms.utils;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;

public class HttpUtil {
	
	public static void write(HttpServletResponse response, String as_Msg) {
		
        write(response, as_Msg, "text/html", "UTF-8");
    }
	
	public static void write(HttpServletResponse response, String as_Msg, String as_ContentType, String as_Charset) {
		
		PrintWriter writer = null;
		
		try {
			
			as_ContentType = StringUtils.trimToEmpty(as_ContentType);
			
			if (as_ContentType.length() == 0) {
				
				as_ContentType = "text/html";
			}

			as_Charset = StringUtils.trimToEmpty(as_Charset);
			
			if (as_Charset.length() == 0) {
				
				as_Charset = "UTF-8";
			}
			
			response.setContentType((new StringBuilder(String.valueOf(as_ContentType))).append("; charset=").append(as_Charset).toString());
		
			writer = response.getWriter();
			writer.write(as_Msg);
			writer.flush();
		} 
		catch (IOException e) {
			
			e.printStackTrace();
		}
		finally {

			if (writer != null) {
				
				writer.close();
			}
		}
	}
}